/*
 * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
 *
 * https://www.mall4j.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.api.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.app.dto.FaceBaseDto;
import com.yami.shop.bean.model.FaceBase;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.service.FaceBaseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import cn.hutool.core.bean.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 人脸底图接口
 * @author AI Assistant
 */
@RestController
@RequestMapping("/faceBase")
@Tag(name = "人脸底图接口")
public class FaceBaseController {

    @Autowired
    private FaceBaseService faceBaseService;

    /**
     * 获取人脸底图列表（分页）
     */
    @GetMapping("/page")
    @Operation(summary = "获取人脸底图列表" , description = "分页获取人脸底图列表")
    @Parameter(name = "faceType", description = "底图类型（1:男性, 2:女性, 3:通用）", required = false)
    @Parameter(name = "status", description = "状态（0:禁用, 1:启用）", required = false)
    public ServerResponseEntity<IPage<FaceBaseDto>> page(
            @RequestParam(value = "faceType", required = false) Integer faceType,
            @RequestParam(value = "status", required = false) Integer status,
            PageParam<FaceBase> page) {
        
        IPage<FaceBase> faceBasePage = faceBaseService.pageByFaceTypeAndStatus(page, faceType, status);
        IPage<FaceBaseDto> faceBaseDtoPage = faceBasePage.convert(faceBase -> {
            FaceBaseDto faceBaseDto = BeanUtil.copyProperties(faceBase, FaceBaseDto.class);
            return faceBaseDto;
        });
        
        return ServerResponseEntity.success(faceBaseDtoPage);
    }

    /**
     * 获取所有人脸底图列表
     */
    @GetMapping("/list")
    @Operation(summary = "获取所有人脸底图列表" , description = "获取所有人脸底图列表")
    @Parameter(name = "faceType", description = "底图类型（1:男性, 2:女性, 3:通用）", required = false)
    @Parameter(name = "status", description = "状态（0:禁用, 1:启用）", required = false)
    public ServerResponseEntity<List<FaceBaseDto>> list(
            @RequestParam(value = "faceType", required = false) Integer faceType,
            @RequestParam(value = "status", required = false) Integer status) {
        
        List<FaceBase> faceBaseList = faceBaseService.listByFaceTypeAndStatus(faceType, status);
        List<FaceBaseDto> faceBaseDtoList = BeanUtil.copyToList(faceBaseList, FaceBaseDto.class);
        
        return ServerResponseEntity.success(faceBaseDtoList);
    }

    /**
     * 获取人脸底图详情
     */
    @GetMapping("/info")
    @Operation(summary = "获取人脸底图详情" , description = "根据底图ID获取人脸底图详情")
    @Parameter(name = "baseId", description = "底图ID", required = true)
    public ServerResponseEntity<FaceBaseDto> info(@RequestParam("baseId") Long baseId) {
        
        FaceBase faceBase = faceBaseService.getById(baseId);
        if (faceBase == null) {
            return ServerResponseEntity.success();
        }
        
        FaceBaseDto faceBaseDto = BeanUtil.copyProperties(faceBase, FaceBaseDto.class);
        return ServerResponseEntity.success(faceBaseDto);
    }

    /**
     * 根据类型获取启用人脸底图列表
     */
    @GetMapping("/listByType")
    @Operation(summary = "根据类型获取启用人脸底图列表" , description = "根据底图类型获取启用的底图列表")
    @Parameter(name = "faceType", description = "底图类型（1:男性, 2:女性, 3:通用）", required = true)
    public ServerResponseEntity<List<FaceBaseDto>> listByType(@RequestParam("faceType") Integer faceType) {
        
        List<FaceBase> faceBaseList = faceBaseService.listByFaceTypeAndStatus(faceType, 1);
        List<FaceBaseDto> faceBaseDtoList = BeanUtil.copyToList(faceBaseList, FaceBaseDto.class);
        
        return ServerResponseEntity.success(faceBaseDtoList);
    }
}